/**
 * Created by Admin on 2018-05-12.
 */
(()=>{
	window.PageModel = class PageModel extends Model {
		static get table() {return 'page'};
		
		getName(value) { return this.get('name', value); }
		setName(value) { return this.set('name', value); }
		getParent(value) { return this.get('category', value); }
		setParent(value) { return this.set('category', value); }
		getCategory(value) { return this.get('category', value); }
		setCategory(value) { return this.set('category', value); }
		getIcon(value) { return this.get('icon', value); }
		setIcon(value) { return this.set('icon', value); }
		getPosition(value) { return this.get('position', value); }
		setPosition(value) { return this.set('position', value); }
		getIdxEmpty(value) { return this.get('idx_empty', value); }
		setIdxEmpty(value) { return this.set('idx_empty', value); }
		
		getAllBlocks() {
			if(!this.getId()) {
				return [];
			}
			
			let blockCollector = new BlockModelCollector;
			blockCollector.where('page_id', this.getId());
			blockCollector.where(COL('type').eq(BlockModel.TYPE.GROUP)).sort('position', 'ASC');
			return blockCollector.load().get();
		}
		
		toString() {
			let allGroupBlock = this.getAllBlocks();
			
			let text = `===== ${this.getName()} =====\n`;
			
			for(let i=0; i<allGroupBlock.length; i++) {
				text += allGroupBlock[i].toString() + "\n";
			}
			
			return text;
		}
	};
	
	Core.setToParentWindow('PageModel', PageModel);
})();


